/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import Models.Room;
import Models.University;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trang_000
 */
public class UniversityDAO {
    public Connection con;
    public UniversityDAO(){
        con = DBFactory.createConnection("dormitoryv2");
    }
    
    public List<University> getAllUniversity(){
        List<University> results = new ArrayList<>();
        
        try {
            //get parent categories
            String sqlst = "SELECT * FROM university";
            PreparedStatement ps = con.prepareStatement(sqlst);
            
            ResultSet rs = ps.executeQuery();

            while (rs.next()) {
                int id = rs.getInt("universityID");
                String name = rs.getString("name");
                String address = rs.getString("address");
                
                University uni = new University(id, name, address);
                //add to results
                results.add(uni);
            }
        } catch (SQLException ex) {
            Logger.getLogger(RoomDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return results;
    }
}
